package logic

import (
	"context"
	"tieba/tiebarpc/tiebarpc"

	"tieba/api/internal/svc"
	"tieba/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TieZiAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTieZiAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TieZiAddLogic {
	return &TieZiAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TieZiAddLogic) TieZiAdd(req *types.TieZiAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.TieBaRpc.TieZiAdd(l.ctx, &tiebarpc.TieZiAddRequest{
		TieId:   req.TieId,
		UserId:  req.UserId,
		Title:   req.Title,
		Content: req.Content,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "发布帖子成功",
		Data:    add,
	}, nil
	return
}
